﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

/*
 * Puppet
 *
 *
 * 依赖：
 *
 *
 * ！不写重复代码！
 * @author TTun
 * @date 7/12/2017 5:16:56 PM
 */
namespace TTGameEngine {
public class BuffReadInfo : MonoBehaviour {

    public BuffConfigInfo[] buffInfos;
    public Dictionary<int, BuffConfigInfo> readBuffInfo;

    static BuffReadInfo instance;

    public static BuffReadInfo Instance {
        get {
            if(instance == null) {
                instance = GameObject.FindObjectOfType<BuffReadInfo>();
            }
            return instance;
        }
    }
    void Awake() {
        if(instance == null) {
            instance = this;
            RebuildBuffInfo();
        }
    }

    void RebuildBuffInfo() {
        readBuffInfo = new Dictionary<int, BuffConfigInfo>();
        for(int i = 0; i < buffInfos.Length; i++) {
            if(buffInfos[i] != null) {
                int id = buffInfos[i].buffID;
                if(!readBuffInfo.ContainsKey(id)) {
                    readBuffInfo.Add(id, buffInfos[i]);
                }
            }
        }
    }

    public BuffConfigInfo GetBuffConfig(int id) {
        if(readBuffInfo.ContainsKey(id)) {
            return readBuffInfo[id];
        }
        return null;
    }

    //概率是否可以添加此buff
    public bool IsAddBuff(int id) {
        if(readBuffInfo.ContainsKey(id)) {
            int randomvalue = UnityEngine.Random.Range(0, 100);
            return randomvalue < readBuffInfo[id].buffRatio;
        }
        return false;
    }
}

}